package cn.edu.gduf.luowowo;

import cn.edu.gduf.luowowo.website.web.interceptor.LoginInterceptor;
import cn.edu.gduf.luowowo.website.web.resolver.UserInfoResolver;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@SpringBootApplication
@EnableDubbo
public class WebSite implements WebMvcConfigurer{
    public static void main(String[] args) {
        SpringApplication.run(WebSite.class, args);
    }

    @Bean
    public UserInfoResolver userInfoResolver(){
        return new UserInfoResolver();
    }

    /**
     * 添加自定义的参数解析器
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userInfoResolver());
    }

    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/styles/**");
    }

}
